package com.example.leetcode.solution;

import java.util.ArrayList;
import java.util.List;

public class Solution30 {
    public static List<Integer> findSubstring(String s, String[] words) {
        List<Integer> result = new ArrayList<>();
        List<String> allWords = new ArrayList<>();
        List<Integer> indexContainers = new ArrayList<>();
//        conbinsString(words,allWords,0,new ArrayList<>(),indexContainers);
        System.out.println(allWords);
        for(String word: words){
            int i = s.indexOf(word);
            String temp = s;
            int start = 0;
            int index = 0;
            int step = 0;
            while(i !=- 1){
                if(start != 0){
                    index = start + i;
                }else{
                    index = i;
                }
                if(!result.contains(index)){
                    result.add(index);
                }
                if(++step > s.length()){
                    break;
                }
                temp = s.substring(step,s.length());
                start = step;
                i = temp.indexOf(word);
            }
        }
        return result;
    }

    public static void conbinsString(String[] str, List<String> result, int index, List<String> combination,List<Integer> indexContainers) {
        if (index == str.length ) {
            StringBuffer stringBuffer = new StringBuffer();
            combination.forEach(s -> {
                stringBuffer.append(s);
            });
            result.add(stringBuffer.toString());
            indexContainers = new ArrayList<>();
        } else {
            for (int i = 0; i < str.length; i++) {
                if(!indexContainers.contains(i)){
                    indexContainers.add(i);
                    combination.add(str[i]);
                    conbinsString(str, result, index + 1, combination,indexContainers);
                    combination.remove(index);
                    indexContainers.remove(index);
                }
            }
        }
    }
}
